package vivek.project.pocketmoney.expenses
{
	import mx.collections.ISummaryCalculator;
	import mx.collections.SummaryField2;

	/**
	 *  The DefaultSummaryCalculator class provides summary calculation logic for
	 *  <code>SUM</code>, <code>MIN</code>, <code>MAX</code>, <code>AVG</code>, and <code>COUNT</code> operations.
	 *
	 *  @see mx.collections.SummaryField2
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 9
	 *  @playerversion AIR 1.1
	 *  @productversion Flex 4
	 *   This implementation is to calculate summary for Multiplication
	 */
	public class BudgetSummaryCalculator implements ISummaryCalculator
	{
		public function summaryCalculationBegin(field:SummaryField2):Object
		{
			var dataField:String=field.dataField;
			var summ:Object={};
			summ[dataField]=new Object();
			summ[dataField].actual=0;
			summ[dataField].budget=0;
			return summ;
		}
		/**
		 *  @inheritDoc
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 9
		 *  @playerversion AIR 1.1
		 *  @productversion Flex 4
		 */
		public function calculateSummary(data:Object, field:SummaryField2, rowData:Object):void
		{
			var dataField:String=field.dataField;
			var value:Number=rowData.data[dataField].budget;
			data[dataField].budget=data[dataField].budget + value;
			data[dataField].actual=data[dataField].actual + rowData.data[dataField].actual;
			;
		}
		/**
		 *  @inheritDoc
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 9
		 *  @playerversion AIR 1.1
		 *  @productversion Flex 4
		 */
		public function returnSummary(data:Object, field:SummaryField2):Number
		{
			return data[field.dataField].budget;
		}
		/**
		 *  @inheritDoc
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 9
		 *  @playerversion AIR 1.1
		 *  @productversion Flex 4
		 */
		public function summaryOfSummaryCalculationBegin(value:Object, field:SummaryField2):Object
		{
			var newObj:Object={};
			for (var p:String in value)
			{
				newObj[p]=value[p];
			}
			return newObj;
		}
		/**
		 *  @inheritDoc
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 9
		 *  @playerversion AIR 1.1
		 *  @productversion Flex 4
		 */
		public function calculateSummaryOfSummary(oldValue:Object, newValue:Object, field:SummaryField2):void
		{
			var p:String;
			for (p in newValue)
			{
				oldValue[p].actual+=newValue[p].actual;
				oldValue[p].budget+=newValue[p].budget;
			}
		}
		/**
		 *  @inheritDoc
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 9
		 *  @playerversion AIR 1.1
		 *  @productversion Flex 4
		 */
		public function returnSummaryOfSummary(oldValue:Object, field:SummaryField2):Number
		{
			var summary:Number=0;
			var dataField:String=field.dataField;
			summary=oldValue[dataField].budget;
			return summary;
		}
	}
}